/**
 * 字段类型枚举
 */
export enum FieldType {
  STRING = 'string',
  NUMBER = 'number',
  BOOLEAN = 'boolean',
  DATE = 'date',
  ENUM = 'enum',
  OBJECT = 'object',
  ARRAY = 'array',
  REFERENCE = 'reference'
}

/**
 * 字段验证规则
 */
export interface FieldValidation {
  required?: boolean;
  minLength?: number;
  maxLength?: number;
  min?: number;
  max?: number;
  pattern?: string;
  message?: string;
  custom?: string; // 自定义验证函数
}

/**
 * 枚举字段选项
 */
export interface EnumOption {
  label: string;
  value: string | number | boolean;
}

/**
 * 数据模型字段
 */
export interface ModelField {
  name: string;
  type: FieldType;
  label: string;
  description?: string;
  defaultValue?: unknown;
  validation?: FieldValidation;
  options?: EnumOption[]; // 用于枚举类型
  referenceModel?: string; // 用于引用类型
  fields?: ModelField[]; // 用于对象和数组类型
  required?: boolean;
  isKey?: boolean; // 是否为主键
  isSearchable?: boolean; // 是否可搜索
  isDisplayed?: boolean; // 是否在列表中显示
}

/**
 * 关联类型
 */
export enum RelationType {
  ONE_TO_ONE = 'oneToOne',
  ONE_TO_MANY = 'oneToMany',
  MANY_TO_ONE = 'manyToOne',
  MANY_TO_MANY = 'manyToMany'
}

/**
 * 模型关联
 */
export interface ModelRelation {
  name: string;
  type: RelationType;
  sourceField: string;
  targetModel: string;
  targetField: string;
}

/**
 * CRUD 操作配置
 */
export interface CrudConfig {
  create?: boolean;
  read?: boolean;
  update?: boolean;
  delete?: boolean;
  pagination?: boolean;
  filter?: boolean;
  sort?: boolean;
}

/**
 * 数据模型定义
 */
export interface Model {
  name: string;
  label: string;
  description?: string;
  fields: ModelField[];
  relations?: ModelRelation[];
  crudConfig?: CrudConfig;
  primaryKey?: string;
  displayField?: string; // 展示字段
} 